package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

const apiKey = "4192d8c40d80eac23128784fdb27fb15"

func main() {
	endpoint := "https://api.zerossl.com/acme/ecc/v2/issue"

	// 准备请求数据
	data := map[string]interface{}{
		"ip_addresses":              []string{"111.229.176.202"},
		"certificate_validity_days": 90,
	}

	jsonData, err := json.Marshal(data)
	if err != nil {
		fmt.Println("JSON marshaling error:", err)
		return
	}

	// 发送 POST 请求
	req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(jsonData))
	if err != nil {
		fmt.Println("Request creation error:", err)
		return
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+apiKey)

	client := http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Request execution error:", err)
		return
	}
	defer resp.Body.Close()

	// 处理响应
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Response reading error:", err)
		return
	}

	fmt.Println("Response:", string(body))
}
